export const state = () => ({
  historyList: []
})

export const mutations = {
  setHistory(state, data) {
    // state.historyList.unshift(data);

    // 当历史记录列表长度大于3时
    // 截取倒数第1起的3个数据
    if(state.historyList.length>3){
      state.historyList.splice(-1,3)
    }

    // console.log('什么情况',state.historyList.splice(-1,5));

    // 假设历史记录中不存在相同的状况
    let flag = false;

    state.historyList.forEach(el=>{
      if(
        el.departCity === data.departCity &&
        el.destCity === data.destCity &&
        el.departDate === data.departDate 
      ){
        flag = true;
      }
    })

    if(!flag){
      state.historyList.unshift(data);
    }
  }
}
